/**
 * 
 */
package kr.co.insoft.publicmesh.controller.eventchain.eventchain;

import kr.co.insoft.core.model.eventchain.eventchain.EventChainEntityModel;
import kr.co.insoft.core.model.paging.EventChainPagingModel;
import kr.co.insoft.core.service.eventchain.eventchain.EventChainService;
import kr.co.insoft.framework.constant.EventChainTypes;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * @author skpark
 * 
 */
@Controller
@RequestMapping(value = "eventchain/eventchain")
public class EventChainController {

	@Autowired
	EventChainService eventChainService;

	private static final Logger logger = LoggerFactory
			.getLogger(EventChainController.class);

	final String TILES_PAGE_PREFIX = "tiles/eventchain/eventchain";
	final String SINGLE_PAGE_PREFIX = "eventchain/eventchain";

	/**
	 * Event Chain Tree
	 * 
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "main")
	public String main(Model model) throws Exception {
		return TILES_PAGE_PREFIX + "/main";
	}

	/**
	 * EventChain 목록
	 * 
	 * @param model
	 * @param eventChainPagingModel
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "lists", method = RequestMethod.POST)
	@ResponseStatus(HttpStatus.OK)
	public String lists(
			Model model,
			@ModelAttribute("eventChainPagingModel") EventChainPagingModel eventChainPagingModel)
			throws Exception {

		model.addAttribute("chainTypes", EventChainTypes.values());
		model.addAttribute("eventChainPagingModel",
				eventChainService.getLists(eventChainPagingModel));

		return SINGLE_PAGE_PREFIX + "/lists";
	}

	@RequestMapping(value = "createForm", method = RequestMethod.POST)
	public String callingForm(Model model, @RequestParam("types") String types,
			@RequestParam("targetid") String targetid) throws Exception {
		/*switch (types.toLowerCase()) {
		case "project":
			model.addAttribute(new ProjectEntityModel());
			break;
		case "service":
			model.addAttribute(orchestrationService
					.createServiceForm(targetid));
			break;
		case "vmcomposite":
			model.addAttribute("hatypes", HATypes.values());
			model.addAttribute(orchestrationService
					.createCompositeForm(targetid));
			break;			
		default:
			throw new NotFoundException(ExceptionCode.NOT_FOUND_EXCEPTION);
		}*/

		model.addAttribute(new EventChainEntityModel());
		return SINGLE_PAGE_PREFIX + "/createForm";
	}

}
